package test.api;

import java.net.UnknownHostException;

import keter.framework.util.PropertiesUtil;

import com.mongodb.DB;
import com.mongodb.MongoClient;

public class MongoDb{

    private static MongoDb instance;

    private DB db;
    
    private MongoDb() {
        // MongoClient mongoClient = new MongoClient();
        // MongoClient mongoClient = new MongoClient( "localhost" );
        // MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
        MongoClient mongoClient;
        try {
            PropertiesUtil pl = new PropertiesUtil("classpath:keter-mongo.properties");
            mongoClient = new MongoClient(pl.get("mongo.host"));
            db = mongoClient.getDB(pl.get("mongo.db"));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

    public static MongoDb getInstance() {
        if (instance == null) {
            instance = new MongoDb();
        }
        return instance;
    }

    public DB getDb() {
        return this.db;
    }
}